package Socket.UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @author chetaifu
 */
public class SocketServer {
    public static void main(String[] args) {
        try {
            byte[] bytes = new byte[1024];
            // 数据报(datagram socket) socket基于UDP, 只能在UDP中使用
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
            DatagramSocket socket = new DatagramSocket(8088);
            socket.receive(packet);
            String receiveMsg = new String(packet.getData(), 0, packet.getLength());
            System.out.println(receiveMsg);

            socket.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
